package com.example.myapplication.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.myapplication.network.LaunchInfo
import com.example.myapplication.ui.VideoFolder
import com.example.myapplication.ui.VideoItem

class AppViewModel : ViewModel() {
    val launchData: MutableLiveData<LaunchInfo> = MutableLiveData<LaunchInfo>()

    val videoList: MutableLiveData<ArrayList<VideoItem>> = MutableLiveData<ArrayList<VideoItem>>()

    val folderMap: MutableLiveData<Map<String, VideoFolder>> =
        MutableLiveData<Map<String, VideoFolder>>()


    val folderList: LiveData<List<VideoFolder>>
        get() {
            val keyList: ArrayList<String>? =
                folderMap.value?.keys?.let { ArrayList(it) } // TreeMap/LinkedHashMap可直接转换

            val values: ArrayList<VideoFolder> = arrayListOf()
            keyList?.forEach { key ->
                folderMap.value?.get(key)?.let { values.add(it) }
            }

            return MutableLiveData(values)
        }

}